import type { UserInfo } from '@vben/types';

import { client } from './client';

// import { requestClient } from '#/api/request';
export namespace SystemRoleApi {
  export interface SystemRole {
    [key: string]: any;
    id: string;
    name: string;
    permissions: string[];
    remark?: string;
    status: 0 | 1;
  }
}
/**
 * 获取用户信息
 */
export async function getUserInfoApi() {
  // return requestClient.get<UserInfo>('/user/info');
  const { data: result } = await client.user.getCurrentUser();
  if (result.success) {
    return {
      avatar: result.data?.avatarUrl || '',
      username: result.data?.username || '',
      userId: `${result.data?.id}` || '',
      realName: result.data?.displayName || '',
      desc: result.data?.displayName || '',
      roles: result.data?.role ? [result.data?.role] : [],
    } as UserInfo;
  } else {
    throw new Error(result.message || '获取用户信息失败');
  }
}
